home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / wwbbs31_source.lha / WWBBS / StartSessionSrc / startsession.c < prev   
Encoding:
C/C++ Source or Header  |  1995-01-28  |  2.6 KB  |  123 lines

  1. #include <exec/types.h>
  2. #include <dos/dos.h>
  3. #include <libraries/wwbbs.h>
  4. #include <utility/tagitem.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #include <proto/exec.h>
  10. #include <proto/dos.h>
  11. #include <proto/wwbbs.h>
  12.  
  13. #include "Data:Programs/Include/wwbbs_commands.h"
  14.  
  15. #include "startsession_rev.h"
  16.  
  17. char *ver=VERSTAG;
  18.  
  19. struct Library *WorldWideBase;
  20.  
  21. char *template[]={
  22.     "-BAUD",NULL };
  23.  
  24. ULONG send_message(BYTE *,BYTE *,UBYTE,struct TagItem *);
  25.  
  26. void main(int argc,char **argv)
  27.     {
  28.         ULONG baud=0;
  29.         BYTE id[33];
  30.         if(argc<2)
  31.             exit(RETURN_FAIL);
  32.         if(!(WorldWideBase=OpenLibrary("wwbbs.library",0)))
  33.             exit(RETURN_FAIL);
  34.         if(strlen(argv[1])>32)
  35.             exit(RETURN_FAIL);
  36.         strcpy(id,argv[1]);
  37.         {
  38.             int match=NULL,i;
  39.             for(i=2;i<argc;i++)
  40.                 {
  41.                     switch(match)
  42.                         {
  43.                             case 0:
  44.                                 {
  45.                                     int j=0;
  46.                                     while(template[j])
  47.                                         {
  48.                                             if(!stricmp(argv[i],template[j]))
  49.                                                 {
  50.                                                     match=j+1;
  51.                                                     break;
  52.                                                 }
  53.                                             else
  54.                                                 j++;
  55.                                         }
  56.                                 }
  57.                                 break;
  58.                             case 1:
  59.                                 baud=atol(argv[i]);
  60.                                 match=NULL;
  61.                                 break;
  62.                         }
  63.                 }
  64.         }
  65.         {
  66.             UBYTE nd_type=0;
  67.             ULONG nd_baud=0;
  68.             BOOL nd_frontend=FALSE;
  69.             GetConfigTags(CFGTAG_Path,"Nodes",CFGTAG_Name,id,NDTAG_Type,&nd_type,NDTAG_Baud,&nd_baud,NDTAG_FrontEnd,&nd_frontend,TAG_END);
  70.             if(nd_type==NDTYP_Remote)
  71.                 {
  72.                     if(nd_frontend)
  73.                         {
  74.                             struct TagItem tags[2];
  75.                             tags[0].ti_Tag=NDSESSIONTAG_Baud;
  76.                             tags[0].ti_Data=(baud) ? baud : nd_baud;
  77.                             tags[1].ti_Tag=TAG_END;
  78.                             tags[1].ti_Data=0;
  79.                             if(!send_message("WWBBS Front End",id,NDCMD_Session,&tags[0]))
  80.                                 printf("Unable to spawn node `%s'.\n",id);
  81.                         }
  82.                     else
  83.                         printf("Node `%s' is not configured to be a front end.\n");
  84.                 }
  85.             else
  86.                 printf("Node `%s' is not a remote node.\n");
  87.         }
  88.         CloseLibrary(WorldWideBase);
  89.         exit(RETURN_OK);
  90.     }
  91.  
  92. ULONG send_message(BYTE *basename,BYTE *id,UBYTE cmd,struct TagItem *tags)
  93.     {
  94.         ULONG ret=NULL;
  95.         BYTE name[64];
  96.         struct MsgPort *port=NULL,*replyport;
  97.         struct CommandMessage msg={0};
  98.         if(id)
  99.             sprintf(name,"%s.%s",basename,id);
  100.         else
  101.             strcpy(name,basename);
  102.         if(replyport=CreateMsgPort())
  103.             {
  104.                 msg.cm_Message.mn_Node.ln_Type=NT_MESSAGE;
  105.                 msg.cm_Message.mn_Length=sizeof(struct CommandMessage);
  106.                 msg.cm_Message.mn_ReplyPort=replyport;
  107.                 msg.cm_Command=cmd;
  108.                 msg.cm_Data=(ULONG) tags;
  109.                 Forbid();
  110.                 if(port=FindPort(name))
  111.                     PutMsg(port,(struct Message *) &msg);
  112.                 Permit();
  113.                 if(port)
  114.                     {
  115.                         WaitPort(replyport);
  116.                         if(GetMsg(replyport))
  117.                             ret=msg.cm_Data;
  118.                     }
  119.                 DeleteMsgPort(replyport);
  120.             }
  121.         return(ret);
  122.     }
  123.